/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rhythm.commons.net;


import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

/**
 * A class that needs to be extended to authenticate an email user account
 * @author jboyd
 */
public class EmailPasswordAuthenticator extends Authenticator
{

    String username, password;

    /**
     * The constructor for the EmailPasswordAuthenticator, the username/password
     * combination when constructed will be used by the overridden function when 
     * needed
     * @param username
     * @param password
     */
    public EmailPasswordAuthenticator(String username, String password)
    {
        this.username = username;
        this.password = password;
    }

    /**
     * This function is automatically called when the email session attempts to do 
     * something that requires password confimation
     * @return A PasswordAuthentication object that contains the username/password
     * combination included when this object was instantiated
     */
    @Override
    public PasswordAuthentication getPasswordAuthentication()
    {
        try
        {
            return new PasswordAuthentication(this.username, this.password);
        } catch (Exception e)
        {
            System.out.println(e.getMessage());
            return null;
        }

    }
}
    
